export default {
    data() {
        return {
            customized: {
                name: '',
                tel: '',
                unit: '',
                date: '',
                type: '1',
                num: '',
                intro: '',
                base: '石家庄',
            },
            news: {
                tab: {
                    active: 0,
                    list: [
                        {
                            name: '公司活动',
                            id: 0,
                        },
                        {
                            name: '公告展示',
                            id: 1,
                        },
                        {
                            name: '最新动态',
                            id: 2,
                        },
                    ]
                },
                list: [],
                loading: true
            },
            story: {
                tab: {
                    active: 3,
                    list: [
                        {
                            name: '案例展示',
                            id: 3,
                        },
                        {
                            name: '活动展示',
                            id: 4,
                        }
                    ]
                },
                list: []
            },
            base: {
                list: [],
                banner: []
            },
            course: {
                list: []
            },
            teacher: {
                list: []
            },
        }
    },
    async mounted() {
        this.getBanner()
        this.handlerTab(0)
        this.getCourse()
        this.getStory()
        this.getBase()
        this.getTeacher()
    },
    methods: {
        handlerTab(id) {
            this.news.tab.active = id
            this.news.loading = true
            if (id === 0) {
                this.getHot()
            } else {
                this.getNews()
            }
        },
        handlerStoryTab(id) {
            console.log(id)
            this.story.tab.active = id
            this.getStory()
        },
        async getNews() {
            try {
                const {data} = await this.$api.news.list({
                    tYPE: this.news.tab.active,
                    page: 1,
                    rows: 4,
                })
                this.news.list = data.rows
            } catch (e) {
                console.error(e)
            }
            this.news.loading = false
        },
        async getBanner() {
            try {
                const {data} = await this.$api.base.banner()
                let arr = []
                for (let i in data[0]) {
                    if (i.includes('pic')) {
                        arr.push(data[0][i])
                    }
                }
                console.log(data[0])
                this.base.banner = arr
            } catch (e) {
                console.error(e)
            }
        },
        async getHot() {
            try {
                const {data} = await this.$api.story.list({
                    page: 1,
                    rows: 4,
                })
                this.news.list = data.list
            } catch (e) {
            }
            this.news.loading = false
        },
        async getCourse() {
            try {
                const {data} = await this.$api.course.list({
                    page: 1,
                    rows: 10,
                    seqtype: '4',
                    seque: 'desc',
                })
                // console.log(data)
                this.course.list = data.list.map(item => {
                    item.courseTimeList.sort((a, b) => {
                        return a.sellamount - b.sellamount
                    })
                    item.money = item.courseTimeList[0] ? item.courseTimeList[0].sellamount : 0
                    return item
                })
            } catch (e) {
                console.error(e)
            }
        },
        async getBase() {
            try {
                const {data} = await this.$api.base.list()
                const list = await this.$api.base.detail(data[0].deptId)
                console.log(list)
                this.base.list = list.data
            } catch (e) {
                console.error(e)
            }
        },
        async getStory() {
            try {
                const {data} = await this.$api.news.list({
                    page: 1,
                    rows: 4,
                    tYPE: this.story.tab.active,
                })
                this.story.list = data.rows
            } catch (e) {
                console.error(e)
            }
        },
        async getTeacher() {
            try {
                const {data} = await this.$api.teacher.list({
                    page: 1,
                    rows: 4,
                })
                this.teacher.list = data.list
                // console.log(data)
            } catch (e) {
                console.error(e)
            }
        }
    }
}
